package com.hnqcgczy.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/***
 * 清空登tuId录状态， 跳转到首页
 */
@WebServlet("/loginout")
public class LoginOutServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //清空session
        req.getSession().removeAttribute("tuId");

        //清除cookie信息
//        Cookie[] cks= req.getCookies();
//        if(cks!=null&&cks.length>0) {
//            for (Cookie ck : cks) {
//                if (ck.getName().equals("tuId")) {
//                  //清空cookie
//                    ck.setMaxAge(0);
//                    resp.addCookie(ck);
//                }
//            }
//        }

        //重定向到首页
        resp.sendRedirect("/index.jsp");
    }
}
